package com.stone.ssm.controller;

import com.stone.ssm.model.User;
import com.stone.ssm.server.IUserServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


@Slf4j
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserServer userService;

    @RequestMapping(value = "/test",method = RequestMethod.GET)
    public String test(int id, Model model){
        int userId = id;
        System.out.println("userId:"+userId);
        return "index";
    }

    @RequestMapping(value = "/{userId}",method = RequestMethod.GET)
    @ResponseBody
    public User getUserByPrimaryKey(@PathVariable("userId") int userId){
        return userService.getUserById(userId);
    }
}
